package com.person.jc.config;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.ext.handler.UrlSkipHandler;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;
import com.person.jc.interceptor.LoginInterceptor;
import com.person.jc.interceptor.SessionInterceptor;
import com.person.jc.web.CommonController;
import com.person.jc.web.IndexController;
import com.person.jc.web.base.car.BdCarInfoController;
import com.person.jc.web.base.customer.BdCustomerController;
import com.person.jc.web.base.device.BdDeviceInfoController;
import com.person.jc.web.base.device.BdDevicePartsController;
import com.person.jc.web.base.device.BdDeviceRelationController;
import com.person.jc.web.base.equip.BdEquipmentController;
import com.person.jc.web.base.fault.BdFaultInfoController;
import com.person.jc.web.base.notice.BdNoticeController;
import com.person.jc.web.base.notice.MyNoticeController;
import com.person.jc.web.base.sign.BdSignController;
import com.person.jc.web.base.standard.BdStandardDeviceController;
import com.person.jc.web.base.standard.BdStandardMatterController;
import com.person.jc.web.base.standard.BdStandardMeasureScopeController;
import com.person.jc.web.base.unqualified.BdUnqualifiedController;
import com.person.jc.web.base.verify.BdVerifyBasisController;
import com.person.jc.web.buy.BsBuyApplyController;
import com.person.jc.web.buy.BsBuyAuditController;
import com.person.jc.web.buy.BsBuyLogController;
import com.person.jc.web.buy.BsBuyStoreController;
import com.person.jc.web.buy.BsPartsConfirmController;
import com.person.jc.web.buy.BsPartsOutlogController;
import com.person.jc.web.car.BdCarLogController;
import com.person.jc.web.car.BdCarReturnController;
import com.person.jc.web.car.BdCarServiceInfoController;
import com.person.jc.web.car.BdCarUseController;
import com.person.jc.web.finance.BsBuyTicketController;
import com.person.jc.web.finance.BsOrderBillingController;
import com.person.jc.web.finance.BuyTicketLogController;
import com.person.jc.web.finance.PayBuyController;
import com.person.jc.web.frame.FrameIndexController;
import com.person.jc.web.login.LoginController;
import com.person.jc.web.security.TsCrudLogController;
import com.person.jc.web.security.TsDeptController;
import com.person.jc.web.security.TsRoleController;
import com.person.jc.web.security.TsRoleVclController;
import com.person.jc.web.security.TsUserController;
import com.person.jc.web.security.TsUserVclController;
import com.person.jc.web.security.TsVisitLogController;
import com.person.jc.web.service.BsBillingController;
import com.person.jc.web.service.BsOrderController;
import com.person.jc.web.service.BsRepairConfirmController;
import com.person.jc.web.service.MyBsOrderController;
import com.person.jc.web.template.DynamicTemplateManageController;
import com.person.jc.web.template.TemplateManageController;
import com.person.jc.web.test.assign.BsTaskAssignController;
import com.person.jc.web.test.certificate.MakeController;
import com.person.jc.web.test.certificate.SendController;
import com.person.jc.web.test.inspect.MyInspectController;
import com.person.jc.web.test.inspect.MyRepairController;
import com.person.jc.web.test.inspect.MyTestingController;

/**
 * API引导式配置
 */
public class GlobalConfig extends JFinalConfig {
	
	/**
	 * 配置常量
	 */
	public void configConstant(Constants me) {
		// 加载少量必要配置，随后可用PropKit.get(...)获取值
		PropKit.use("config/jfinal.properties");
		PropKit.use("config/selectTag.properties");
		me.setDevMode(PropKit.getBoolean("devMode", true));
		me.setViewType(ViewType.JSP);
		me.setBaseViewPath("WEB-INF/views/");
		me.setError404View("/static/commons/404.jsp");
		me.setError500View("/static/commons/500.jsp");
		
	}
	
	/**
	 * 配置路由
	 */
	public void configRoute(Routes me) {
		me.add("/", IndexController.class, "/");	// 默认页
		me.add("/login", LoginController.class, "/");	// 登陆
		me.add("/frameIndex", FrameIndexController.class, "/");	//首页
		
		me.add("/common" , CommonController.class);
		
		// 业务管理
		me.add("/bsOrder" , BsOrderController.class,"/service");//接单
		me.add("/myBsOrder" , MyBsOrderController.class,"/service");//接单
		me.add("/repairConfirm" , BsRepairConfirmController.class,"/service/confirm");//维修确认
		me.add("/billing",BsBillingController.class,"/service/billing");	// 开票申请
		
		// 检测管理
		me.add("/myTesting" , MyTestingController.class,"/test/inspect/testing");//我的检测任务
		me.add("/myInspect" , MyInspectController.class,"/test/inspect/inspect");//我的检查任务
		me.add("/myRepair" , MyRepairController.class,"/test/inspect/repair");//我的检修任务
		me.add("/taskAssign" , BsTaskAssignController.class,"/test/assign");//任务分配
		
		// 采购管理
		me.add("/buyApply" , BsBuyApplyController.class,"/buy/apply");//采购申请
		me.add("/buyAudit" , BsBuyAuditController.class,"/buy/audit");//采购审核
		me.add("/buyStore" , BsBuyStoreController.class,"/buy/store");//采购入库
		me.add("/partsConfirm", BsPartsConfirmController.class,"/buy/confirm");//配件确认
		me.add("/partsOut", BsPartsOutlogController.class,"/buy/outlog");//配件出库
		me.add("/buyLog" , BsBuyLogController.class,"/buy/log");//采购申请历史
		
		// 财务管理
		me.add("/orderBilling" , BsOrderBillingController.class,"/finance/billing");//采购票据
		me.add("/buyTicket" , BsBuyTicketController.class,"/finance/buyTicket");//采购票据
		me.add("/payBuy" , PayBuyController.class,"/finance/payBuy");//采购付款
		me.add("/ticketLog" , BuyTicketLogController.class,"/finance/ticketLog");//采购申请历史
		
		// 用车管理
		me.add("/carUse" , BdCarUseController.class,"/car/use");//用车管理-我要用车
		me.add("/carReturn" , BdCarReturnController.class,"/car/return");//用车管理-我要还车
		me.add("/carLog" , BdCarLogController.class,"/car/log");//用车管理-用车记录
		me.add("/carService" , BdCarServiceInfoController.class,"/car/service");//用车统计-车辆保养管理
		
		// 基础信息
		me.add("/equipment" , BdEquipmentController.class,"/base/equip");//计量设备管理
		me.add("/standardMatter" , BdStandardMatterController.class,"/base/standard/matter");//标准物质管理
		me.add("/standardDevice" , BdStandardDeviceController.class,"/base/standard/device");//计量标准装置
		me.add("/unqualified" , BdUnqualifiedController.class,"/base/unqualified");//不合格原因
		me.add("/verify" , BdVerifyBasisController.class,"/base/verify");//检定依据
		me.add("/customer" , BdCustomerController.class,"/base/customer");//客户单位管理
		me.add("/sign" , BdSignController.class,"/base/sign");//人名签章管理
		me.add("/deviceInfo" , BdDeviceInfoController.class,"/base/device/info");//仪器名称维护
		me.add("/standardMeasureScope" , BdStandardMeasureScopeController.class,"/base/standard/measureScope");//气体设备量程
		me.add("/car" , BdCarInfoController.class,"/base/car");//车辆信息
		me.add("/notice" , BdNoticeController.class,"/base/notice");//通知公告
		me.add("/myNotice" , MyNoticeController.class,"/base/myNotice");//我的通知
		me.add("/fault" , BdFaultInfoController.class,"/base/fault");//设备故障现象
		me.add("/deviceParts" , BdDevicePartsController.class,"/base/device/parts");//设备配件管理
		me.add("/deviceRelation" , BdDeviceRelationController.class,"/base/device/relation");//标准装置配置
		
		me.add("/template" , TemplateManageController.class,"/template");//模板管理
		me.add("/dynaTemplate" , DynamicTemplateManageController.class,"/templateDynamic");//动态模板管理

		me.add("/makeController" , MakeController.class,"/test/certificate/make");//动态模板管理
		me.add("/sendController" , SendController.class,"/test/certificate/send");//动态模板管理


		// 系统管理
		me.add("/user" , TsUserController.class,"/security/tsUser");//用户管理
		me.add("/role" , TsRoleController.class,"/security/tsRole");//角色管理
		me.add("/roleVcl" , TsRoleVclController.class,"/security/tsRoleVcl");//角色授权
		me.add("/userVcl" , TsUserVclController.class,"/security/tsUserVcl");//用户授权
		me.add("/dept" , TsDeptController.class,"/security/tsDept");//部门管理
		me.add("/visitlog" , TsVisitLogController.class,"/security/tsVisitLog");//登陆日志
		me.add("/crudlog" , TsCrudLogController.class,"/security/tsCrudLog");//操作日志
	}
	
	public static C3p0Plugin createC3p0Plugin() {
		return new C3p0Plugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
	}
	
	/**
	 * 配置插件
	 */
	public void configPlugin(Plugins me) {
		// 配置C3p0数据库连接池插件
		C3p0Plugin C3p0Plugin = createC3p0Plugin();
		me.add(C3p0Plugin);
		
		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(C3p0Plugin);
		arp.setShowSql(true);
		me.add(arp);
		// 所有配置在 MappingKit 中搞定
		//_MappingKit.mapping(arp);
	}
	
	/**
	 * 配置全局拦截器
	 */
	public void configInterceptor(Interceptors me) {
		LoginInterceptor login = new LoginInterceptor();
		SessionInterceptor session = new SessionInterceptor();
		me.add(login);
		me.add(session);
	}
	
	/**
	 * 配置处理器
	 */
	public void configHandler(Handlers me) {
		me.add(new UrlSkipHandler("/UploadImg",false));
	}



	public static String getTemplateDataRealPath(){
		return PropKit.get("TemplateData_RealPath");
	}


	public static String getShadowsRealPath(){
		return PropKit.get("Shadows_RealPath");
	}
	
	/**
	 * 建议使用 JFinal 手册推荐的方式启动项目
	 * 运行此 main 方法可以启动项目，此main方法可以放置在任意的Class类定义中，不一定要放于此
	 */
	public static void main(String[] args) {
		JFinal.start("WebRoot", 8080, "/", 5);
	}
}
